package com.gc.controller.teachclassServlet;

import com.gc.entity.TeachClass;
import com.gc.repository.TeachClassRepository;
import com.gc.repository.impl.TeachClassRepositoryImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "teachclassAdd", value = "/teachclassAdd")
public class teachclassAdd extends HttpServlet {
    TeachClassRepository teachclassRepository = new TeachClassRepositoryImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Gson gson = new Gson();


        boolean res = teachclassRepository.Add(new TeachClass(
                null,
                request.getParameter("classname"),
                request.getParameter("classid"),
                request.getParameter("cid"),
                request.getParameter("tid")));
        if(res) {
            response.getWriter().write(gson.toJson(R.ok().data("ok")));
        } else {
            response.getWriter().write(gson.toJson(R.error()));
        }


    }
}
